<!--  -->
<template>
    <el-card>
        <div class='header' slot="header">
            <div class="category-header">
                <span>销售额类别占比</span>
                <el-radio-group v-model="value">
                    <el-radio-button label="全部渠道"></el-radio-button>
                    <el-radio-button label="线上"></el-radio-button>
                    <el-radio-button label="门店"></el-radio-button>
                </el-radio-group>
            </div>
            <div>
                <div class="charts" ref="charts"></div>
            </div>
        </div>
    </el-card>
</template>
    
<script>
//这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
//例如：import 《组件名称》 from '《组件路径》';
import echarts from "echarts";
export default {
    //import引入的组件需要注入到对象中才能使用
    data(){
        return {
            value:"全部渠道",
        }
    },
    components: {},
    mounted() {
        let mychart = echarts.init(this.$refs.charts);
        mychart.setOption({
            title: {
                text: "视频",
                subtext: 1048,
                left: "center",
                top: "center",
            },
            tooltip: {
                trigger: "item",
            },
            series: [
                {
                    name: "Access From",
                    type: "pie",
                    radius: ["40%", "70%"],
                    avoidLabelOverlap: false,
                    itemStyle: {
                        borderRadius: 10,
                        borderColor: "#fff",
                        borderWidth: 2,
                    },
                    label: {
                        show: true,
                        position: "outsize",
                    },
                    labelLine: {
                        show: true,
                    },
                    data: [
                        { value: 1048, name: "视频" },
                        { value: 735, name: "Direct" },
                        { value: 580, name: "Email" },
                        { value: 484, name: "Union Ads" },
                        { value: 300, name: "Video Ads" },
                    ],
                },
            ],
        });
  
        //绑定事件
        mychart.on("mouseover",(params)=>{
            //获取鼠标移动上去的那个数据
            const {name,value} = params.data;
            //重新设置标题
            mychart.setOption({
                title:{
                    text:name,
                    subtext:value
                }
            })
        })
    }

}
</script>
<style scoped>
.category-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.header {
  border-bottom: 1px solid #eee;
}
.charts {
  width: 100%;
  height: 300px;
}
</style>
